diff options
41 files changed, 351 insertions, 61 deletions
diff --git a/.ci/templates/build-msvc.yml b/.ci/templates/build-msvc.yml index c379dd757..427028e08 100644 --- a/.ci/templates/build-msvc.yml +++ b/.ci/templates/build-msvc.yml @@ -9,7 +9,7 @@ parameters: steps: - script: choco install vulkan-sdk displayName: 'Install vulkan-sdk' -- script: refreshenv && mkdir build && cd build && cmake -E env CXXFLAGS="/Gw /GA /Gr /Ob2" cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_POLICY_DEFAULT_CMP0069=NEW -DYUZU_USE_BUNDLED_QT=1 -DYUZU_USE_BUNDLED_SDL2=1 -DYUZU_USE_QT_WEB_ENGINE=ON -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${COMPAT} -DYUZU_TESTS=OFF -DUSE_DISCORD_PRESENCE=ON -DENABLE_QT_TRANSLATION=ON -DDISPLAY_VERSION=${{ parameters['version'] }} -DCMAKE_BUILD_TYPE=Release -DYUZU_CRASH_DUMPS=ON .. && cd .. +- script: refreshenv && mkdir build && cd build && cmake -E env CXXFLAGS="/Gw /GA /Gr /Ob2" cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_POLICY_DEFAULT_CMP0069=NEW -DENABLE_LTO=ON -DYUZU_USE_BUNDLED_QT=1 -DYUZU_USE_BUNDLED_SDL2=1 -DYUZU_USE_QT_WEB_ENGINE=ON -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${COMPAT} -DYUZU_TESTS=OFF -DUSE_DISCORD_PRESENCE=ON -DENABLE_QT_TRANSLATION=ON -DDISPLAY_VERSION=${{ parameters['version'] }} -DCMAKE_BUILD_TYPE=Release -DYUZU_CRASH_DUMPS=ON .. && cd .. displayName: 'Configure CMake' - task: MSBuild@1 displayName: 'Build' diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a3de9e2..274eebe8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,8 @@ option(YUZU_USE_BUNDLED_VCPKG "Use vcpkg for yuzu dependencies" "${MSVC}") option(YUZU_CHECK_SUBMODULES "Check if submodules are present" ON) +option(YUZU_ENABLE_LTO "Enable link-time optimization" OFF) + CMAKE_DEPENDENT_OPTION(YUZU_USE_FASTER_LD "Check if a faster linker is available" ON "NOT WIN32" OFF) if (YUZU_USE_BUNDLED_VCPKG) diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h index 1245a5086..26d4e76dc 100644 --- a/src/common/scratch_buffer.h +++ b/src/common/scratch_buffer.h @@ -23,6 +23,7 @@ public: buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} ~ScratchBuffer() = default; + ScratchBuffer(ScratchBuffer&&) = default; /// This will only grow the buffer's capacity if size is greater than the current capacity. /// The previously held data will remain intact. diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 749ac213f..84955030b 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -59,6 +59,7 @@ void LogSettings() { values.use_asynchronous_gpu_emulation.GetValue()); log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue()); log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue()); + log_setting("Renderer_AsyncASTC", values.async_astc.GetValue()); log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); @@ -219,6 +220,7 @@ void RestoreGlobalState(bool is_powered_on) { values.use_asynchronous_gpu_emulation.SetGlobal(true); values.nvdec_emulation.SetGlobal(true); values.accelerate_astc.SetGlobal(true); + values.async_astc.SetGlobal(true); values.use_vsync.SetGlobal(true); values.shader_backend.SetGlobal(true); values.use_asynchronous_shaders.SetGlobal(true); diff --git a/src/common/settings.h b/src/common/settings.h index 6d27dd5ee..512ecff69 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -453,6 +453,7 @@ struct Values { SwitchableSetting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; SwitchableSetting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; SwitchableSetting<bool> accelerate_astc{true, "accelerate_astc"}; + SwitchableSetting<bool> async_astc{false, "async_astc"}; SwitchableSetting<bool> use_vsync{true, "use_vsync"}; SwitchableSetting<ShaderBackend, true> shader_backend{ShaderBackend::GLSL, ShaderBackend::GLSL, ShaderBackend::SPIRV, "shader_backend"}; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ff5502d87..70fa1edf5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -861,3 +861,7 @@ endif() if (YUZU_USE_PRECOMPILED_HEADERS) target_precompile_headers(core PRIVATE precompiled_headers.h) endif() + +if (YUZU_ENABLE_LTO) + set_property(TARGET core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 6d5a3dead..a29c9a6f8 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -363,7 +363,17 @@ void EmulatedController::ReloadInput() { SetMotion(callback, index); }, }); - motion_devices[index]->ForceUpdate(); + + // Restore motion state + auto& emulated_motion = controller.motion_values[index].emulated; + auto& motion = controller.motion_state[index]; + emulated_motion.ResetRotations(); + emulated_motion.ResetQuaternion(); + motion.accel = emulated_motion.GetAcceleration(); + motion.gyro = emulated_motion.GetGyroscope(); + motion.rotation = emulated_motion.GetRotations(); + motion.orientation = emulated_motion.GetOrientation(); + motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); } for (std::size_t index = 0; index < camera_devices.size(); ++index) { diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index eef6edf4b..0dd66c1cc 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp @@ -10,6 +10,8 @@ MotionInput::MotionInput() { // Initialize PID constants with default values SetPID(0.3f, 0.005f, 0.0f); SetGyroThreshold(ThresholdStandard); + ResetQuaternion(); + ResetRotations(); } void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { @@ -20,11 +22,19 @@ void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { accel = acceleration; + + accel.x = std::clamp(accel.x, -AccelMaxValue, AccelMaxValue); + accel.y = std::clamp(accel.y, -AccelMaxValue, AccelMaxValue); + accel.z = std::clamp(accel.z, -AccelMaxValue, AccelMaxValue); } void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { gyro = gyroscope - gyro_bias; + gyro.x = std::clamp(gyro.x, -GyroMaxValue, GyroMaxValue); + gyro.y = std::clamp(gyro.y, -GyroMaxValue, GyroMaxValue); + gyro.z = std::clamp(gyro.z, -GyroMaxValue, GyroMaxValue); + // Auto adjust drift to minimize drift if (!IsMoving(IsAtRestRelaxed)) { gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); @@ -61,6 +71,10 @@ void MotionInput::ResetRotations() { rotations = {}; } +void MotionInput::ResetQuaternion() { + quat = {{0.0f, 0.0f, -1.0f}, 0.0f}; +} + bool MotionInput::IsMoving(f32 sensitivity) const { return gyro.Length() >= sensitivity || accel.Length() <= 0.9f || accel.Length() >= 1.1f; } diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h index 9180bb9aa..e2c1bbf95 100644 --- a/src/core/hid/motion_input.h +++ b/src/core/hid/motion_input.h @@ -20,6 +20,9 @@ public: static constexpr float IsAtRestStandard = 0.01f; static constexpr float IsAtRestThight = 0.005f; + static constexpr float GyroMaxValue = 5.0f; + static constexpr float AccelMaxValue = 7.0f; + explicit MotionInput(); MotionInput(const MotionInput&) = default; @@ -40,6 +43,7 @@ public: void EnableReset(bool reset); void ResetRotations(); + void ResetQuaternion(); void UpdateRotation(u64 elapsed_time); void UpdateOrientation(u64 elapsed_time); @@ -69,7 +73,7 @@ private: Common::Vec3f derivative_error; // Quaternion containing the device orientation - Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; + Common::Quaternion<f32> quat; // Number of full rotations in each axis Common::Vec3f rotations; diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 1495d64de..1241fcdff 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -76,6 +76,8 @@ public: {141, nullptr, "RefreshNetworkServiceLicenseCacheAsync"}, // 5.0.0+ {142, nullptr, "RefreshNetworkServiceLicenseCacheAsyncIfSecondsElapsed"}, // 5.0.0+ {150, nullptr, "CreateAuthorizationRequest"}, + {160, nullptr, "RequiresUpdateNetworkServiceAccountIdTokenCache"}, + {161, nullptr, "RequireReauthenticationOfNetworkServiceAccount"}, }; // clang-format on @@ -136,7 +138,10 @@ public: {140, nullptr, "GetNetworkServiceLicenseCache"}, // 5.0.0+ {141, nullptr, "RefreshNetworkServiceLicenseCacheAsync"}, // 5.0.0+ {142, nullptr, "RefreshNetworkServiceLicenseCacheAsyncIfSecondsElapsed"}, // 5.0.0+ + {143, nullptr, "GetNetworkServiceLicenseCacheEx"}, {150, nullptr, "CreateAuthorizationRequest"}, + {160, nullptr, "RequiresUpdateNetworkServiceAccountIdTokenCache"}, + {161, nullptr, "RequireReauthenticationOfNetworkServiceAccount"}, {200, nullptr, "IsRegistered"}, {201, nullptr, "RegisterAsync"}, {202, nullptr, "UnregisterAsync"}, @@ -242,6 +247,7 @@ public: {100, nullptr, "GetRequestWithTheme"}, {101, nullptr, "IsNetworkServiceAccountReplaced"}, {199, nullptr, "GetUrlForIntroductionOfExtraMembership"}, // 2.0.0 - 5.1.0 + {200, nullptr, "ApplyAsyncWithAuthorizedToken"}, }; // clang-format on @@ -647,9 +653,11 @@ public: {0, nullptr, "EnsureAuthenticationTokenCacheAsync"}, {1, nullptr, "LoadAuthenticationTokenCache"}, {2, nullptr, "InvalidateAuthenticationTokenCache"}, + {3, nullptr, "IsDeviceAuthenticationTokenCacheAvailable"}, {10, nullptr, "EnsureEdgeTokenCacheAsync"}, {11, nullptr, "LoadEdgeTokenCache"}, {12, nullptr, "InvalidateEdgeTokenCache"}, + {13, nullptr, "IsEdgeTokenCacheAvailable"}, {20, nullptr, "EnsureApplicationAuthenticationCacheAsync"}, {21, nullptr, "LoadApplicationAuthenticationTokenCache"}, {22, nullptr, "LoadApplicationNetworkServiceClientConfigCache"}, diff --git a/src/core/hle/service/acc/acc_su.cpp b/src/core/hle/service/acc/acc_su.cpp index b6bfd6155..d9882ecd3 100644 --- a/src/core/hle/service/acc/acc_su.cpp +++ b/src/core/hle/service/acc/acc_su.cpp @@ -55,6 +55,10 @@ ACC_SU::ACC_SU(std::shared_ptr<Module> module_, std::shared_ptr<ProfileManager> {290, nullptr, "ProxyProcedureForGuestLoginWithNintendoAccount"}, {291, nullptr, "ProxyProcedureForFloatingRegistrationWithNintendoAccount"}, {299, nullptr, "SuspendBackgroundDaemon"}, + {900, nullptr, "SetUserUnqualifiedForDebug"}, + {901, nullptr, "UnsetUserUnqualifiedForDebug"}, + {902, nullptr, "ListUsersUnqualifiedForDebug"}, + {910, nullptr, "RefreshFirmwareSettingsForDebug"}, {997, nullptr, "DebugInvalidateTokenCacheForUser"}, {998, nullptr, "DebugSetUserStateClose"}, {999, nullptr, "DebugSetUserStateOpen"}, diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index adb482941..9a7316e27 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -226,6 +226,8 @@ IDebugFunctions::IDebugFunctions(Core::System& system_) {30, nullptr, "RequestLaunchApplicationWithUserAndArgumentForDebug"}, {31, nullptr, "RequestLaunchApplicationByApplicationLaunchInfoForDebug"}, {40, nullptr, "GetAppletResourceUsageInfo"}, + {50, nullptr, "AddSystemProgramIdAndAppletIdForDebug"}, + {51, nullptr, "AddOperationConfirmedLibraryAppletIdForDebug"}, {100, nullptr, "SetCpuBoostModeForApplet"}, {101, nullptr, "CancelCpuBoostModeForApplet"}, {110, nullptr, "PushToAppletBoundChannelForDebug"}, @@ -237,6 +239,8 @@ IDebugFunctions::IDebugFunctions(Core::System& system_) {131, nullptr, "FriendInvitationClearApplicationParameter"}, {132, nullptr, "FriendInvitationPushApplicationParameter"}, {140, nullptr, "RestrictPowerOperationForSecureLaunchModeForDebug"}, + {200, nullptr, "CreateFloatingLibraryAppletAccepterForDebug"}, + {300, nullptr, "TerminateAllRunningApplicationsForDebug"}, {900, nullptr, "GetGrcProcessLaunchedSystemEvent"}, }; // clang-format on @@ -1853,6 +1857,8 @@ IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_) {31, nullptr, "GetWriterLockAccessorEx"}, {40, nullptr, "IsSleepEnabled"}, {41, nullptr, "IsRebootEnabled"}, + {50, nullptr, "LaunchSystemApplet"}, + {51, nullptr, "LaunchStarter"}, {100, nullptr, "PopRequestLaunchApplicationForDebug"}, {110, nullptr, "IsForceTerminateApplicationDisabledForDebug"}, {200, nullptr, "LaunchDevMenu"}, diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index 7264f23f9..1bbf057cb 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp @@ -129,6 +129,9 @@ AOC_U::AOC_U(Core::System& system_) {101, &AOC_U::CreatePermanentEcPurchasedEventManager, "CreatePermanentEcPurchasedEventManager"}, {110, nullptr, "CreateContentsServiceManager"}, {200, nullptr, "SetRequiredAddOnContentsOnContentsAvailabilityTransition"}, + {300, nullptr, "SetupHostAddOnContent"}, + {301, nullptr, "GetRegisteredAddOnContentPath"}, + {302, nullptr, "UpdateCachedList"}, }; // clang-format on diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index e01f87356..3db3fe188 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -362,6 +362,8 @@ HwOpus::HwOpus(Core::System& system_) : ServiceFramework{system_, "hwopus"} { {5, &HwOpus::GetWorkBufferSizeEx, "GetWorkBufferSizeEx"}, {6, nullptr, "OpenHardwareOpusDecoderForMultiStreamEx"}, {7, &HwOpus::GetWorkBufferSizeForMultiStreamEx, "GetWorkBufferSizeForMultiStreamEx"}, + {8, nullptr, "GetWorkBufferSizeExEx"}, + {9, nullptr, "GetWorkBufferSizeForMultiStreamExEx"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/btm/btm.cpp b/src/core/hle/service/btm/btm.cpp index eebf85e03..419da36c4 100644 --- a/src/core/hle/service/btm/btm.cpp +++ b/src/core/hle/service/btm/btm.cpp @@ -72,32 +72,36 @@ private: void AcquireBleScanEvent(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(scan_event->GetReadableEvent()); } void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(connection_event->GetReadableEvent()); } void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(service_discovery_event->GetReadableEvent()); } void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(config_event->GetReadableEvent()); } diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 48f7bbf95..0da67235f 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -63,6 +63,7 @@ IAppletResource::IAppletResource(Core::System& system_, MakeControllerWithServiceContext<Controller_NPad>(HidController::NPad, shared_memory); MakeController<Controller_Gesture>(HidController::Gesture, shared_memory); MakeController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor, shared_memory); + MakeController<Controller_Stubbed>(HidController::DebugMouse, shared_memory); MakeControllerWithServiceContext<Controller_Palma>(HidController::Palma, shared_memory); // Homebrew doesn't try to activate some controllers, so we activate them by default @@ -74,6 +75,7 @@ IAppletResource::IAppletResource(Core::System& system_, GetController<Controller_Stubbed>(HidController::CaptureButton).SetCommonHeaderOffset(0x5000); GetController<Controller_Stubbed>(HidController::InputDetector).SetCommonHeaderOffset(0x5200); GetController<Controller_Stubbed>(HidController::UniquePad).SetCommonHeaderOffset(0x5A00); + GetController<Controller_Stubbed>(HidController::DebugMouse).SetCommonHeaderOffset(0x3DC00); // Register update callbacks npad_update_event = Core::Timing::CreateEvent( @@ -236,6 +238,7 @@ Hid::Hid(Core::System& system_) {1, &Hid::ActivateDebugPad, "ActivateDebugPad"}, {11, &Hid::ActivateTouchScreen, "ActivateTouchScreen"}, {21, &Hid::ActivateMouse, "ActivateMouse"}, + {26, nullptr, "ActivateDebugMouse"}, {31, &Hid::ActivateKeyboard, "ActivateKeyboard"}, {32, &Hid::SendKeyboardLockKeyEvent, "SendKeyboardLockKeyEvent"}, {40, nullptr, "AcquireXpadIdEventHandle"}, @@ -2379,6 +2382,8 @@ public: {20, nullptr, "DeactivateMouse"}, {21, nullptr, "SetMouseAutoPilotState"}, {22, nullptr, "UnsetMouseAutoPilotState"}, + {25, nullptr, "SetDebugMouseAutoPilotState"}, + {26, nullptr, "UnsetDebugMouseAutoPilotState"}, {30, nullptr, "DeactivateKeyboard"}, {31, nullptr, "SetKeyboardAutoPilotState"}, {32, nullptr, "UnsetKeyboardAutoPilotState"}, @@ -2494,6 +2499,7 @@ public: {2000, nullptr, "DeactivateDigitizer"}, {2001, nullptr, "SetDigitizerAutoPilotState"}, {2002, nullptr, "UnsetDigitizerAutoPilotState"}, + {2002, nullptr, "ReloadFirmwareDebugSettings"}, }; // clang-format on diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index a397012a5..9ace83129 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -33,6 +33,7 @@ enum class HidController : std::size_t { NPad, Gesture, ConsoleSixAxisSensor, + DebugMouse, Palma, MaxControllers, diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp index da1c8415c..07199d5d5 100644 --- a/src/core/hle/service/hid/hidbus.cpp +++ b/src/core/hle/service/hid/hidbus.cpp @@ -91,7 +91,7 @@ std::optional<std::size_t> HidBus::GetDeviceIndexFromHandle(BusHandle handle) co if (handle.abstracted_pad_id == device_handle.abstracted_pad_id && handle.internal_index == device_handle.internal_index && handle.player_number == device_handle.player_number && - handle.bus_type == device_handle.bus_type && + handle.bus_type_id == device_handle.bus_type_id && handle.is_valid == device_handle.is_valid) { return i; } @@ -123,7 +123,7 @@ void HidBus::GetBusHandle(Kernel::HLERequestContext& ctx) { continue; } if (static_cast<Core::HID::NpadIdType>(handle.player_number) == parameters.npad_id && - handle.bus_type == parameters.bus_type) { + handle.bus_type_id == static_cast<u8>(parameters.bus_type)) { is_handle_found = true; handle_index = i; break; @@ -140,7 +140,7 @@ void HidBus::GetBusHandle(Kernel::HLERequestContext& ctx) { .abstracted_pad_id = static_cast<u8>(i), .internal_index = static_cast<u8>(i), .player_number = static_cast<u8>(parameters.npad_id), - .bus_type = parameters.bus_type, + .bus_type_id = static_cast<u8>(parameters.bus_type), .is_valid = true, }; handle_index = i; @@ -172,7 +172,7 @@ void HidBus::IsExternalDeviceConnected(Kernel::HLERequestContext& ctx) { LOG_INFO(Service_HID, "Called, abstracted_pad_id={}, bus_type={}, internal_index={}, " "player_number={}, is_valid={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -201,7 +201,7 @@ void HidBus::Initialize(Kernel::HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, abstracted_pad_id={} bus_type={} internal_index={} " "player_number={} is_valid={}, applet_resource_user_id={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid, applet_resource_user_id); is_hidbus_enabled = true; @@ -253,7 +253,7 @@ void HidBus::Finalize(Kernel::HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, abstracted_pad_id={}, bus_type={}, internal_index={}, " "player_number={}, is_valid={}, applet_resource_user_id={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid, applet_resource_user_id); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -301,7 +301,7 @@ void HidBus::EnableExternalDevice(Kernel::HLERequestContext& ctx) { "called, enable={}, abstracted_pad_id={}, bus_type={}, internal_index={}, " "player_number={}, is_valid={}, inval={}, applet_resource_user_id{}", parameters.enable, parameters.bus_handle.abstracted_pad_id, - parameters.bus_handle.bus_type, parameters.bus_handle.internal_index, + parameters.bus_handle.bus_type_id, parameters.bus_handle.internal_index, parameters.bus_handle.player_number, parameters.bus_handle.is_valid, parameters.inval, parameters.applet_resource_user_id); @@ -329,7 +329,7 @@ void HidBus::GetExternalDeviceId(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, abstracted_pad_id={}, bus_type={}, internal_index={}, player_number={}, " "is_valid={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -357,7 +357,7 @@ void HidBus::SendCommandAsync(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, data_size={}, abstracted_pad_id={}, bus_type={}, internal_index={}, " "player_number={}, is_valid={}", - data.size(), bus_handle_.abstracted_pad_id, bus_handle_.bus_type, + data.size(), bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -384,7 +384,7 @@ void HidBus::GetSendCommandAsynceResult(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, abstracted_pad_id={}, bus_type={}, internal_index={}, player_number={}, " "is_valid={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -413,7 +413,7 @@ void HidBus::SetEventForSendCommandAsycResult(Kernel::HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, abstracted_pad_id={}, bus_type={}, internal_index={}, player_number={}, " "is_valid={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -464,7 +464,7 @@ void HidBus::EnableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, t_mem_handle=0x{:08X}, polling_mode={}, abstracted_pad_id={}, bus_type={}, " "internal_index={}, player_number={}, is_valid={}", - t_mem_handle, polling_mode_, bus_handle_.abstracted_pad_id, bus_handle_.bus_type, + t_mem_handle, polling_mode_, bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); @@ -492,7 +492,7 @@ void HidBus::DisableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, abstracted_pad_id={}, bus_type={}, internal_index={}, player_number={}, " "is_valid={}", - bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, + bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid); const auto device_index = GetDeviceIndexFromHandle(bus_handle_); diff --git a/src/core/hle/service/hid/hidbus.h b/src/core/hle/service/hid/hidbus.h index 9a4702021..85ed96e2e 100644 --- a/src/core/hle/service/hid/hidbus.h +++ b/src/core/hle/service/hid/hidbus.h @@ -41,7 +41,7 @@ private: }; // This is nn::hidbus::BusType - enum class BusType : u8 { + enum class BusType : u32 { LeftJoyRail, RightJoyRail, InternalBus, // Lark microphone @@ -54,7 +54,7 @@ private: u32 abstracted_pad_id; u8 internal_index; u8 player_number; - BusType bus_type; + u8 bus_type_id; bool is_valid; }; static_assert(sizeof(BusHandle) == 0x8, "BusHandle is an invalid size"); diff --git a/src/core/hle/service/ncm/ncm.cpp b/src/core/hle/service/ncm/ncm.cpp index 68210a108..4c66cfeba 100644 --- a/src/core/hle/service/ncm/ncm.cpp +++ b/src/core/hle/service/ncm/ncm.cpp @@ -124,6 +124,7 @@ public: {12, nullptr, "InactivateContentMetaDatabase"}, {13, nullptr, "InvalidateRightsIdCache"}, {14, nullptr, "GetMemoryReport"}, + {15, nullptr, "ActivateFsContentStorage"}, }; // clang-format on diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index f59a1a63d..e53bdde52 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -159,6 +159,8 @@ IApplicationManagerInterface::IApplicationManagerInterface(Core::System& system_ {606, nullptr, "GetContentMetaStorage"}, {607, nullptr, "ListAvailableAddOnContent"}, {609, nullptr, "ListAvailabilityAssuredAddOnContent"}, + {610, nullptr, "GetInstalledContentMetaStorage"}, + {611, nullptr, "PrepareAddOnContent"}, {700, nullptr, "PushDownloadTaskList"}, {701, nullptr, "ClearTaskStatusList"}, {702, nullptr, "RequestDownloadTaskList"}, @@ -228,6 +230,7 @@ IApplicationManagerInterface::IApplicationManagerInterface(Core::System& system_ {1900, nullptr, "IsActiveAccount"}, {1901, nullptr, "RequestDownloadApplicationPrepurchasedRights"}, {1902, nullptr, "GetApplicationTicketInfo"}, + {1903, nullptr, "RequestDownloadApplicationPrepurchasedRightsForAccount"}, {2000, nullptr, "GetSystemDeliveryInfo"}, {2001, nullptr, "SelectLatestSystemDeliveryInfo"}, {2002, nullptr, "VerifyDeliveryProtocolVersion"}, @@ -276,8 +279,11 @@ IApplicationManagerInterface::IApplicationManagerInterface(Core::System& system_ {2352, nullptr, "RequestResolveNoDownloadRightsError"}, {2353, nullptr, "GetApplicationDownloadTaskInfo"}, {2354, nullptr, "PrioritizeApplicationBackgroundTask"}, - {2355, nullptr, "Unknown2355"}, - {2356, nullptr, "Unknown2356"}, + {2355, nullptr, "PreferStorageEfficientUpdate"}, + {2356, nullptr, "RequestStorageEfficientUpdatePreferable"}, + {2357, nullptr, "EnableMultiCoreDownload"}, + {2358, nullptr, "DisableMultiCoreDownload"}, + {2359, nullptr, "IsMultiCoreDownloadEnabled"}, {2400, nullptr, "GetPromotionInfo"}, {2401, nullptr, "CountPromotionInfo"}, {2402, nullptr, "ListPromotionInfo"}, @@ -295,6 +301,7 @@ IApplicationManagerInterface::IApplicationManagerInterface(Core::System& system_ {2519, nullptr, "IsQualificationTransitionSupported"}, {2520, nullptr, "IsQualificationTransitionSupportedByProcessId"}, {2521, nullptr, "GetRightsUserChangedEvent"}, + {2522, nullptr, "IsRomRedirectionAvailable"}, {2800, nullptr, "GetApplicationIdOfPreomia"}, {3000, nullptr, "RegisterDeviceLockKey"}, {3001, nullptr, "UnregisterDeviceLockKey"}, @@ -311,6 +318,7 @@ IApplicationManagerInterface::IApplicationManagerInterface(Core::System& system_ {3012, nullptr, "IsApplicationTitleHidden"}, {3013, nullptr, "IsGameCardEnabled"}, {3014, nullptr, "IsLocalContentShareEnabled"}, + {3050, nullptr, "ListAssignELicenseTaskResult"}, {9999, nullptr, "GetApplicationCertificate"}, }; // clang-format on diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index bdb499268..330a66409 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp @@ -954,6 +954,9 @@ BSDCFG::BSDCFG(Core::System& system_) : ServiceFramework{system_, "bsdcfg"} { {10, nullptr, "ClearArpEntries"}, {11, nullptr, "ClearArpEntries2"}, {12, nullptr, "PrintArpEntries"}, + {13, nullptr, "Unknown13"}, + {14, nullptr, "Unknown14"}, + {15, nullptr, "Unknown15"}, }; // clang-format on diff --git a/src/core/hle/service/ssl/ssl.cpp b/src/core/hle/service/ssl/ssl.cpp index dcf47083f..015208593 100644 --- a/src/core/hle/service/ssl/ssl.cpp +++ b/src/core/hle/service/ssl/ssl.cpp @@ -46,6 +46,14 @@ public: {25, nullptr, "GetCipherInfo"}, {26, nullptr, "SetNextAlpnProto"}, {27, nullptr, "GetNextAlpnProto"}, + {28, nullptr, "SetDtlsSocketDescriptor"}, + {29, nullptr, "GetDtlsHandshakeTimeout"}, + {30, nullptr, "SetPrivateOption"}, + {31, nullptr, "SetSrtpCiphers"}, + {32, nullptr, "GetSrtpCipher"}, + {33, nullptr, "ExportKeyingMaterial"}, + {34, nullptr, "SetIoTimeout"}, + {35, nullptr, "GetIoTimeout"}, }; // clang-format on @@ -69,6 +77,8 @@ public: {9, nullptr, "AddPolicyOid"}, {10, nullptr, "ImportCrl"}, {11, nullptr, "RemoveCrl"}, + {12, nullptr, "ImportClientCertKeyPki"}, + {13, nullptr, "GeneratePrivateKeyAndCert"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 2fb631183..0915785d2 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -249,6 +249,9 @@ public: {2053, nullptr, "DestroyIndirectProducerEndPoint"}, {2054, nullptr, "CreateIndirectConsumerEndPoint"}, {2055, nullptr, "DestroyIndirectConsumerEndPoint"}, + {2060, nullptr, "CreateWatermarkCompositor"}, + {2062, nullptr, "SetWatermarkText"}, + {2063, nullptr, "SetWatermarkLayerStacks"}, {2300, nullptr, "AcquireLayerTexturePresentingEvent"}, {2301, nullptr, "ReleaseLayerTexturePresentingEvent"}, {2302, nullptr, "GetDisplayHotplugEvent"}, @@ -279,6 +282,8 @@ public: {6011, nullptr, "EnableLayerAutoClearTransitionBuffer"}, {6012, nullptr, "DisableLayerAutoClearTransitionBuffer"}, {6013, nullptr, "SetLayerOpacity"}, + {6014, nullptr, "AttachLayerWatermarkCompositor"}, + {6015, nullptr, "DetachLayerWatermarkCompositor"}, {7000, nullptr, "SetContentVisibility"}, {8000, nullptr, "SetConductorLayer"}, {8001, nullptr, "SetTimestampTracking"}, diff --git a/src/core/hle/service/vi/vi_m.cpp b/src/core/hle/service/vi/vi_m.cpp index 1ab7fe4ab..7ca44354b 100644 --- a/src/core/hle/service/vi/vi_m.cpp +++ b/src/core/hle/service/vi/vi_m.cpp @@ -14,6 +14,10 @@ VI_M::VI_M(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, static const FunctionInfo functions[] = { {2, &VI_M::GetDisplayService, "GetDisplayService"}, {3, nullptr, "GetDisplayServiceWithProxyNameExchange"}, + {100, nullptr, "PrepareFatal"}, + {101, nullptr, "ShowFatal"}, + {102, nullptr, "DrawFatalRectangle"}, + {103, nullptr, "DrawFatalText32"}, }; RegisterHandlers(functions); } diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index da50e0a24..8b7f9aee9 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp @@ -10,17 +10,25 @@ #include "input_common/drivers/mouse.h" namespace InputCommon { +constexpr int update_time = 10; +constexpr float default_stick_sensitivity = 0.022f; +constexpr float default_motion_sensitivity = 0.008f; constexpr int mouse_axis_x = 0; constexpr int mouse_axis_y = 1; constexpr int wheel_axis_x = 2; constexpr int wheel_axis_y = 3; -constexpr int motion_wheel_y = 4; constexpr PadIdentifier identifier = { .guid = Common::UUID{}, .port = 0, .pad = 0, }; +constexpr PadIdentifier motion_identifier = { + .guid = Common::UUID{}, + .port = 0, + .pad = 1, +}; + constexpr PadIdentifier real_mouse_identifier = { .guid = Common::UUID{}, .port = 1, @@ -37,47 +45,87 @@ Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) PreSetController(identifier); PreSetController(real_mouse_identifier); PreSetController(touch_identifier); + PreSetController(motion_identifier); // Initialize all mouse axis PreSetAxis(identifier, mouse_axis_x); PreSetAxis(identifier, mouse_axis_y); PreSetAxis(identifier, wheel_axis_x); PreSetAxis(identifier, wheel_axis_y); - PreSetAxis(identifier, motion_wheel_y); PreSetAxis(real_mouse_identifier, mouse_axis_x); PreSetAxis(real_mouse_identifier, mouse_axis_y); PreSetAxis(touch_identifier, mouse_axis_x); PreSetAxis(touch_identifier, mouse_axis_y); + + // Initialize variables + mouse_origin = {}; + last_mouse_position = {}; + wheel_position = {}; + last_mouse_change = {}; + last_motion_change = {}; + update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); } void Mouse::UpdateThread(std::stop_token stop_token) { Common::SetCurrentThreadName("Mouse"); - constexpr int update_time = 10; - while (!stop_token.stop_requested()) { - if (Settings::values.mouse_panning) { - // Slow movement by 4% - last_mouse_change *= 0.96f; - const float sensitivity = - Settings::values.mouse_panning_sensitivity.GetValue() * 0.022f; - SetAxis(identifier, mouse_axis_x, last_mouse_change.x * sensitivity); - SetAxis(identifier, mouse_axis_y, -last_mouse_change.y * sensitivity); - } - SetAxis(identifier, motion_wheel_y, 0.0f); + while (!stop_token.stop_requested()) { + UpdateStickInput(); + UpdateMotionInput(); - if (mouse_panning_timout++ > 20) { + if (mouse_panning_timeout++ > 20) { StopPanning(); } std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); } } +void Mouse::UpdateStickInput() { + if (!Settings::values.mouse_panning) { + return; + } + + const float sensitivity = + Settings::values.mouse_panning_sensitivity.GetValue() * default_stick_sensitivity; + + // Slow movement by 4% + last_mouse_change *= 0.96f; + SetAxis(identifier, mouse_axis_x, last_mouse_change.x * sensitivity); + SetAxis(identifier, mouse_axis_y, -last_mouse_change.y * sensitivity); +} + +void Mouse::UpdateMotionInput() { + const float sensitivity = + Settings::values.mouse_panning_sensitivity.GetValue() * default_motion_sensitivity; + + // Slow movement by 7% + if (Settings::values.mouse_panning) { + last_motion_change *= 0.93f; + } else { + last_motion_change.z *= 0.93f; + } + + const BasicMotion motion_data{ + .gyro_x = last_motion_change.x * sensitivity, + .gyro_y = last_motion_change.y * sensitivity, + .gyro_z = last_motion_change.z * sensitivity, + .accel_x = 0, + .accel_y = 0, + .accel_z = 0, + .delta_timestamp = update_time * 1000, + }; + + SetMotion(motion_identifier, 0, motion_data); +} + void Mouse::Move(int x, int y, int center_x, int center_y) { if (Settings::values.mouse_panning) { + mouse_panning_timeout = 0; + auto mouse_change = (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); - mouse_panning_timout = 0; + Common::Vec3<float> motion_change{-mouse_change.y, -mouse_change.x, last_motion_change.z}; const auto move_distance = mouse_change.Length(); if (move_distance == 0) { @@ -93,6 +141,7 @@ void Mouse::Move(int x, int y, int center_x, int center_y) { // Average mouse movements last_mouse_change = (last_mouse_change * 0.91f) + (mouse_change * 0.09f); + last_motion_change = (last_motion_change * 0.69f) + (motion_change * 0.31f); const auto last_move_distance = last_mouse_change.Length(); @@ -116,6 +165,12 @@ void Mouse::Move(int x, int y, int center_x, int center_y) { const float sensitivity = Settings::values.mouse_panning_sensitivity.GetValue() * 0.0012f; SetAxis(identifier, mouse_axis_x, static_cast<float>(mouse_move.x) * sensitivity); SetAxis(identifier, mouse_axis_y, static_cast<float>(-mouse_move.y) * sensitivity); + + last_motion_change = { + static_cast<float>(-mouse_move.y) / 50.0f, + static_cast<float>(-mouse_move.x) / 50.0f, + last_motion_change.z, + }; } } @@ -157,15 +212,19 @@ void Mouse::ReleaseButton(MouseButton button) { SetAxis(identifier, mouse_axis_x, 0); SetAxis(identifier, mouse_axis_y, 0); } + + last_motion_change.x = 0; + last_motion_change.y = 0; + button_pressed = false; } void Mouse::MouseWheelChange(int x, int y) { wheel_position.x += x; wheel_position.y += y; + last_motion_change.z += static_cast<f32>(y) / 100.0f; SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x)); SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y)); - SetAxis(identifier, motion_wheel_y, static_cast<f32>(y) / 100.0f); } void Mouse::ReleaseAllButtons() { @@ -234,6 +293,9 @@ Common::Input::ButtonNames Mouse::GetUIName(const Common::ParamPackage& params) if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) { return Common::Input::ButtonNames::Engine; } + if (params.Has("motion")) { + return Common::Input::ButtonNames::Engine; + } return Common::Input::ButtonNames::Invalid; } diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h index f3b65bdd1..b872c7a0f 100644 --- a/src/input_common/drivers/mouse.h +++ b/src/input_common/drivers/mouse.h @@ -96,6 +96,8 @@ public: private: void UpdateThread(std::stop_token stop_token); + void UpdateStickInput(); + void UpdateMotionInput(); void StopPanning(); Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; @@ -103,9 +105,10 @@ private: Common::Vec2<int> mouse_origin; Common::Vec2<int> last_mouse_position; Common::Vec2<float> last_mouse_change; + Common::Vec3<float> last_motion_change; Common::Vec2<int> wheel_position; bool button_pressed; - int mouse_panning_timout{}; + int mouse_panning_timeout{}; std::jthread update_thread; }; diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 6990a86b9..2ff480ff9 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp @@ -142,14 +142,10 @@ void MappingFactory::RegisterMotion(const MappingData& data) { new_input.Set("port", static_cast<int>(data.pad.port)); new_input.Set("pad", static_cast<int>(data.pad.pad)); - // If engine is mouse map the mouse position as 3 axis motion + // If engine is mouse map it automatically to mouse motion if (data.engine == "mouse") { - new_input.Set("axis_x", 1); - new_input.Set("invert_x", "-"); - new_input.Set("axis_y", 0); - new_input.Set("axis_z", 4); - new_input.Set("range", 1.0f); - new_input.Set("deadzone", 0.0f); + new_input.Set("motion", 0); + new_input.Set("pad", 1); input_queue.Push(new_input); return; } diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 4742bcbe9..e904573d7 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -330,3 +330,7 @@ endif() if (YUZU_USE_PRECOMPILED_HEADERS) target_precompile_headers(video_core PRIVATE precompiled_headers.h) endif() + +if (YUZU_ENABLE_LTO) + set_property(TARGET video_core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index eb6e43a08..b047e7b3d 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -228,8 +228,9 @@ void ApplySwizzle(GLuint handle, PixelFormat format, std::array<SwizzleSource, 4 [[nodiscard]] bool CanBeAccelerated(const TextureCacheRuntime& runtime, const VideoCommon::ImageInfo& info) { - if (IsPixelFormatASTC(info.format)) { - return !runtime.HasNativeASTC() && Settings::values.accelerate_astc.GetValue(); + if (IsPixelFormatASTC(info.format) && !runtime.HasNativeASTC()) { + return Settings::values.accelerate_astc.GetValue() && + !Settings::values.async_astc.GetValue(); } // Disable other accelerated uploads for now as they don't implement swizzled uploads return false; @@ -258,6 +259,14 @@ void ApplySwizzle(GLuint handle, PixelFormat format, std::array<SwizzleSource, 4 return format_info.compatibility_class == store_class; } +[[nodiscard]] bool CanBeDecodedAsync(const TextureCacheRuntime& runtime, + const VideoCommon::ImageInfo& info) { + if (IsPixelFormatASTC(info.format) && !runtime.HasNativeASTC()) { + return Settings::values.async_astc.GetValue(); + } + return false; +} + [[nodiscard]] CopyOrigin MakeCopyOrigin(VideoCommon::Offset3D offset, VideoCommon::SubresourceLayers subresource, GLenum target) { switch (target) { @@ -721,7 +730,9 @@ std::optional<size_t> TextureCacheRuntime::StagingBuffers::FindBuffer(size_t req Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_, GPUVAddr gpu_addr_, VAddr cpu_addr_) : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), runtime{&runtime_} { - if (CanBeAccelerated(*runtime, info)) { + if (CanBeDecodedAsync(*runtime, info)) { + flags |= ImageFlagBits::AsynchronousDecode; + } else if (CanBeAccelerated(*runtime, info)) { flags |= ImageFlagBits::AcceleratedUpload; } if (IsConverted(runtime->device, info.format, info.type)) { diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 9b85dfb5e..80adb70eb 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -1256,11 +1256,12 @@ Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu commit(runtime_.memory_allocator.Commit(original_image, MemoryUsage::DeviceLocal)), aspect_mask(ImageAspectMask(info.format)) { if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { - if (Settings::values.accelerate_astc.GetValue()) { + if (Settings::values.async_astc.GetValue()) { + flags |= VideoCommon::ImageFlagBits::AsynchronousDecode; + } else if (Settings::values.accelerate_astc.GetValue()) { flags |= VideoCommon::ImageFlagBits::AcceleratedUpload; - } else { - flags |= VideoCommon::ImageFlagBits::Converted; } + flags |= VideoCommon::ImageFlagBits::Converted; flags |= VideoCommon::ImageFlagBits::CostlyLoad; } if (runtime->device.HasDebuggingToolAttached()) { diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h index 620565684..e8fa592d2 100644 --- a/src/video_core/texture_cache/image_base.h +++ b/src/video_core/texture_cache/image_base.h @@ -38,6 +38,9 @@ enum class ImageFlagBits : u32 { Rescaled = 1 << 13, CheckingRescalable = 1 << 14, IsRescalable = 1 << 15, + + AsynchronousDecode = 1 << 16, + IsDecoding = 1 << 17, ///< Is currently being decoded asynchornously. }; DECLARE_ENUM_FLAG_OPERATORS(ImageFlagBits) diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 3e2cbb0b0..9dd152fbe 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -85,6 +85,11 @@ void TextureCache<P>::RunGarbageCollector() { } --num_iterations; auto& image = slot_images[image_id]; + if (True(image.flags & ImageFlagBits::IsDecoding)) { + // This image is still being decoded, deleting it will invalidate the slot + // used by the async decoder thread. + return false; + } const bool must_download = image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap); if (!high_priority_mode && @@ -133,6 +138,8 @@ void TextureCache<P>::TickFrame() { sentenced_images.Tick(); sentenced_framebuffers.Tick(); sentenced_image_view.Tick(); + TickAsyncDecode(); + runtime.TickFrame(); critical_gc = 0; ++frame_tick; @@ -777,6 +784,10 @@ void TextureCache<P>::RefreshContents(Image& image, ImageId image_id) { LOG_WARNING(HW_GPU, "MSAA image uploads are not implemented"); return; } + if (True(image.flags & ImageFlagBits::AsynchronousDecode)) { + QueueAsyncDecode(image, image_id); + return; + } auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image)); UploadImageContents(image, staging); runtime.InsertUploadMemoryBarrier(); @@ -990,6 +1001,65 @@ u64 TextureCache<P>::GetScaledImageSizeBytes(const ImageBase& image) { } template <class P> +void TextureCache<P>::QueueAsyncDecode(Image& image, ImageId image_id) { + UNIMPLEMENTED_IF(False(image.flags & ImageFlagBits::Converted)); + LOG_INFO(HW_GPU, "Queuing async texture decode"); + + image.flags |= ImageFlagBits::IsDecoding; + auto decode = std::make_unique<AsyncDecodeContext>(); + auto* decode_ptr = decode.get(); + decode->image_id = image_id; + async_decodes.push_back(std::move(decode)); + + Common::ScratchBuffer<u8> local_unswizzle_data_buffer(image.unswizzled_size_bytes); + const size_t guest_size_bytes = image.guest_size_bytes; + swizzle_data_buffer.resize_destructive(guest_size_bytes); + gpu_memory->ReadBlockUnsafe(image.gpu_addr, swizzle_data_buffer.data(), guest_size_bytes); + auto copies = UnswizzleImage(*gpu_memory, image.gpu_addr, image.info, swizzle_data_buffer, + local_unswizzle_data_buffer); + const size_t out_size = MapSizeBytes(image); + + auto func = [out_size, copies, info = image.info, + input = std::move(local_unswizzle_data_buffer), + async_decode = decode_ptr]() mutable { + async_decode->decoded_data.resize_destructive(out_size); + std::span copies_span{copies.data(), copies.size()}; + ConvertImage(input, info, async_decode->decoded_data, copies_span); + + // TODO: Do we need this lock? + std::unique_lock lock{async_decode->mutex}; + async_decode->copies = std::move(copies); + async_decode->complete = true; + }; + texture_decode_worker.QueueWork(std::move(func)); +} + +template <class P> +void TextureCache<P>::TickAsyncDecode() { + bool has_uploads{}; + auto i = async_decodes.begin(); + while (i != async_decodes.end()) { + auto* async_decode = i->get(); + std::unique_lock lock{async_decode->mutex}; + if (!async_decode->complete) { + ++i; + continue; + } + Image& image = slot_images[async_decode->image_id]; + auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image)); + std::memcpy(staging.mapped_span.data(), async_decode->decoded_data.data(), + async_decode->decoded_data.size()); + image.UploadMemory(staging, async_decode->copies); + image.flags &= ~ImageFlagBits::IsDecoding; + has_uploads = true; + i = async_decodes.erase(i); + } + if (has_uploads) { + runtime.InsertUploadMemoryBarrier(); + } +} + +template <class P> bool TextureCache<P>::ScaleUp(Image& image) { const bool has_copy = image.HasScaled(); const bool rescaled = image.ScaleUp(); diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 485eaabaa..013836933 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h @@ -3,6 +3,7 @@ #pragma once +#include <atomic> #include <deque> #include <limits> #include <mutex> @@ -18,6 +19,7 @@ #include "common/lru_cache.h" #include "common/polyfill_ranges.h" #include "common/scratch_buffer.h" +#include "common/thread_worker.h" #include "video_core/compatible_formats.h" #include "video_core/control/channel_state_cache.h" #include "video_core/delayed_destruction_ring.h" @@ -54,6 +56,14 @@ struct ImageViewInOut { ImageViewId id{}; }; +struct AsyncDecodeContext { + ImageId image_id; + Common::ScratchBuffer<u8> decoded_data; + std::vector<BufferImageCopy> copies; + std::mutex mutex; + std::atomic_bool complete; +}; + using TextureCacheGPUMap = std::unordered_map<u64, std::vector<ImageId>, Common::IdentityHash<u64>>; class TextureCacheChannelInfo : public ChannelInfo { @@ -377,6 +387,9 @@ private: bool ScaleDown(Image& image); u64 GetScaledImageSizeBytes(const ImageBase& image); + void QueueAsyncDecode(Image& image, ImageId image_id); + void TickAsyncDecode(); + Runtime& runtime; VideoCore::RasterizerInterface& rasterizer; @@ -430,6 +443,9 @@ private: u64 modification_tick = 0; u64 frame_tick = 0; + + Common::ThreadWorker texture_decode_worker{1, "TextureDecoder"}; + std::vector<std::unique_ptr<AsyncDecodeContext>> async_decodes; }; } // namespace VideoCommon diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index e8d7c7863..4381eed1d 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -1656,8 +1656,8 @@ void Decompress(std::span<const uint8_t> data, uint32_t width, uint32_t height, const u32 rows = Common::DivideUp(height, block_height); const u32 cols = Common::DivideUp(width, block_width); - Common::ThreadWorker workers{std::max(std::thread::hardware_concurrency(), 2U) / 2, - "ASTCDecompress"}; + static Common::ThreadWorker workers{std::max(std::thread::hardware_concurrency(), 2U) / 2, + "ASTCDecompress"}; for (u32 z = 0; z < depth; ++z) { const u32 depth_offset = z * height * width * 4; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index db68ed259..bb731276e 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -707,6 +707,7 @@ void Config::ReadRendererValues() { ReadGlobalSetting(Settings::values.use_asynchronous_gpu_emulation); ReadGlobalSetting(Settings::values.nvdec_emulation); ReadGlobalSetting(Settings::values.accelerate_astc); + ReadGlobalSetting(Settings::values.async_astc); ReadGlobalSetting(Settings::values.use_vsync); ReadGlobalSetting(Settings::values.shader_backend); ReadGlobalSetting(Settings::values.use_asynchronous_shaders); @@ -1312,9 +1313,7 @@ void Config::SaveRendererValues() { static_cast<u32>(Settings::values.renderer_backend.GetValue(global)), static_cast<u32>(Settings::values.renderer_backend.GetDefault()), Settings::values.renderer_backend.UsingGlobal()); - WriteSetting(QString::fromStdString(Settings::values.renderer_force_max_clock.GetLabel()), - static_cast<u32>(Settings::values.renderer_force_max_clock.GetValue(global)), - static_cast<u32>(Settings::values.renderer_force_max_clock.GetDefault())); + WriteGlobalSetting(Settings::values.renderer_force_max_clock); WriteGlobalSetting(Settings::values.vulkan_device); WriteSetting(QString::fromStdString(Settings::values.fullscreen_mode.GetLabel()), static_cast<u32>(Settings::values.fullscreen_mode.GetValue(global)), @@ -1350,6 +1349,7 @@ void Config::SaveRendererValues() { static_cast<u32>(Settings::values.nvdec_emulation.GetDefault()), Settings::values.nvdec_emulation.UsingGlobal()); WriteGlobalSetting(Settings::values.accelerate_astc); + WriteGlobalSetting(Settings::values.async_astc); WriteGlobalSetting(Settings::values.use_vsync); WriteSetting(QString::fromStdString(Settings::values.shader_backend.GetLabel()), static_cast<u32>(Settings::values.shader_backend.GetValue(global)), diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index cc0155a2c..59fb1b334 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -23,11 +23,13 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { const bool runtime_lock = !system.IsPoweredOn(); ui->use_vsync->setEnabled(runtime_lock); ui->renderer_force_max_clock->setEnabled(runtime_lock); + ui->async_astc->setEnabled(runtime_lock); ui->use_asynchronous_shaders->setEnabled(runtime_lock); ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); ui->renderer_force_max_clock->setChecked(Settings::values.renderer_force_max_clock.GetValue()); ui->use_vsync->setChecked(Settings::values.use_vsync.GetValue()); + ui->async_astc->setChecked(Settings::values.async_astc.GetValue()); ui->use_asynchronous_shaders->setChecked(Settings::values.use_asynchronous_shaders.GetValue()); ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); ui->use_pessimistic_flushes->setChecked(Settings::values.use_pessimistic_flushes.GetValue()); @@ -45,8 +47,6 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { &Settings::values.max_anisotropy); ConfigurationShared::SetHighlight(ui->label_gpu_accuracy, !Settings::values.gpu_accuracy.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->renderer_force_max_clock, - !Settings::values.renderer_force_max_clock.UsingGlobal()); ConfigurationShared::SetHighlight(ui->af_label, !Settings::values.max_anisotropy.UsingGlobal()); } @@ -60,6 +60,8 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() { ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, ui->anisotropic_filtering_combobox); ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync, ui->use_vsync, use_vsync); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.async_astc, ui->async_astc, + async_astc); ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, ui->use_asynchronous_shaders, use_asynchronous_shaders); @@ -91,6 +93,7 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { ui->renderer_force_max_clock->setEnabled( Settings::values.renderer_force_max_clock.UsingGlobal()); ui->use_vsync->setEnabled(Settings::values.use_vsync.UsingGlobal()); + ui->async_astc->setEnabled(Settings::values.async_astc.UsingGlobal()); ui->use_asynchronous_shaders->setEnabled( Settings::values.use_asynchronous_shaders.UsingGlobal()); ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); @@ -108,6 +111,8 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { Settings::values.renderer_force_max_clock, renderer_force_max_clock); ConfigurationShared::SetColoredTristate(ui->use_vsync, Settings::values.use_vsync, use_vsync); + ConfigurationShared::SetColoredTristate(ui->async_astc, Settings::values.async_astc, + async_astc); ConfigurationShared::SetColoredTristate(ui->use_asynchronous_shaders, Settings::values.use_asynchronous_shaders, use_asynchronous_shaders); diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index df557d585..bf1b04749 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h @@ -38,6 +38,7 @@ private: ConfigurationShared::CheckState renderer_force_max_clock; ConfigurationShared::CheckState use_vsync; + ConfigurationShared::CheckState async_astc; ConfigurationShared::CheckState use_asynchronous_shaders; ConfigurationShared::CheckState use_fast_gpu_time; ConfigurationShared::CheckState use_pessimistic_flushes; diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 061885e30..a7dbdc18c 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui @@ -90,6 +90,16 @@ </widget> </item> <item> + <widget class="QCheckBox" name="async_astc"> + <property name="toolTip"> + <string>Enables asynchronous ASTC texture decoding, which may reduce load time stutter. This feature is experimental.</string> + </property> + <property name="text"> + <string>Decode ASTC textures asynchronously (Hack)</string> + </property> + </widget> + </item> + <item> <widget class="QCheckBox" name="use_asynchronous_shaders"> <property name="toolTip"> <string>Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental.</string> diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 3b6dce296..464da3231 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -324,6 +324,7 @@ void Config::ReadValues() { ReadSetting("Renderer", Settings::values.use_asynchronous_shaders); ReadSetting("Renderer", Settings::values.nvdec_emulation); ReadSetting("Renderer", Settings::values.accelerate_astc); + ReadSetting("Renderer", Settings::values.async_astc); ReadSetting("Renderer", Settings::values.use_fast_gpu_time); ReadSetting("Renderer", Settings::values.use_pessimistic_flushes); ReadSetting("Renderer", Settings::values.use_vulkan_driver_pipeline_cache); diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index cf3cc4c4e..20e403400 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -342,6 +342,10 @@ nvdec_emulation = # 0: Off, 1 (default): On accelerate_astc = +# Decode ASTC textures asynchronously. +# 0 (default): Off, 1: On +async_astc = + # Turns on the speed limiter, which will limit the emulation speed to the desired speed limit value # 0: Off, 1: On (default) use_speed_limit = |